home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 1.7 KB | 51 lines | [TEXT/GEOL] |
- Item 0054226 13-Feb-91 09:45PST
-
- From: ALGER Alger, Jeff,VCA
-
- To: LALEKERMAC CSX Technology, W Laleker,SSF,PAS
- MACAPP.TECH$ MacApp Technical
-
- ------------------------------------------------------------------------------
-
- Sub: Re: overloading vs. overriding
-
- Earl,
-
- What you have described is not inheritance. The method B::A does not have
- anything to do with A::A. The terms overloading and overriding are frequently
- confused, so let me attempt to clear up the terms. Both use polymorphism - the
- ability to give several different functions the same name - but there the
- similarity ends.
-
- • Overloading applies WITHIN a single class and has nothing to do with
- inheritance. Overloading allows you to use the same name for several different
- methods of a class, each of which has a different calling sequence. This is
- overloading:
-
- class foo {
- void x(void); // first method
- void x(int); // second method, same name, different args
- };
-
- Notice that both implementations of x() are within the same class.
-
- • Overriding applies to inherited methods and requires a common interface
- (i.e., argument list). This is overriding:
-
- class foo {
- virtual void x(void); // foo version of method
- };
-
- class bar: public foo {
- virtual void x(void); // bar version of method
- };
-
- In all cases, the best way to conceptualize your design is to initially assign
- unique names to all implementations, then layer overloading and overriding on
- top of that design to achieve an optimal interface. It's easy to go batty
- trying to "design-in" polymorphism at an early stage.
-
- Hope this helps,
- Jeff Alger
-
-